package com.cn.lp.converter.demo.converter;


import com.cn.lp.converter.BeanConverter;
import com.cn.lp.converter.MergeResult;
import com.cn.lp.converter.annotation.*;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@ConverterMapper
public interface TestBeanMethodConverter extends BeanConverter<TestBeanMethodConverter.EntityA, TestBeanMethodConverter.EntityB> {

    @Data
    class EntityA {

        private HashMap<String, Integer> emptyData;

        private int changeData;

        private int assignData;

        private long notChangeData;

        private String sameData;

        private String notSameData;

    }

    @Data
    class EntityB {

        private HashMap<String, Integer> emptyData;

        private int changeData;

        private String assignData;

        private long notChangeData;

        private int sameData;

        private long notSameData;

    }

    @TypeChangeMethod
    default long notSameChangeType(String obj) {
        return 2999;
    }

    @JudgeSameMethod
    default boolean judgeSame(String param1, long param2) {
        return false;
    }

    @JudgeSameMethod
    default boolean judgeSame(String param1, int param2) {
        return true;
    }

    @TypeChangeMethod
    default int sameChangeType(String obj) {
        return 10086;
    }

    @JudgeEmptyMethod
    default boolean judgeEmpty(HashMap<String, Integer> map) {
        return map == null || map.size() <= 0;
    }

    @DefaultValueMethod
    default HashMap<String, Integer> defaultValue() {
        HashMap<String, Integer> dataMap = new HashMap<>();
        dataMap.put("defaultValue", 0);
        return dataMap;
    }

    @TypeChangeMethod(fieldNameFilter = @FieldNameFilter(assignFieldName = "assignData"))
    default String assignChangeType(int obj) {
        return "assignValue";
    }

    @Override
    default EntityB postConvertTo(EntityA source, EntityB target) {
        System.out.println("ConvertTo 之后触发");
        return target;
    }

    @Override
    default MergeResult<EntityB> postMergeTo(EntityA source, EntityB target, MergeResult<EntityB> result) {
        System.out.println("MergeTo 之后触发");
        return result;
    }

}
